<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="销售订单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'salesOrdNo', validatorRules.salesOrdNo]" placeholder="请输入销售订单号"></a-input>
        </a-form-item>
        <a-form-item label="交流采样 合格/不合格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'acsamplingRes', validatorRules.acsamplingRes]" placeholder="请输入交流采样 合格/不合格"></a-input>
        </a-form-item>
        <a-form-item label="开入回路 合格/不合格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'openinLoopRes', validatorRules.openinLoopRes]" placeholder="请输入开入回路 合格/不合格"></a-input>
        </a-form-item>
        <a-form-item label="开出回路 合格/不合格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'openoutLoopRes', validatorRules.openoutLoopRes]" placeholder="请输入开出回路 合格/不合格"></a-input>
        </a-form-item>
        <a-form-item label="网络风暴 合格/不合格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'cyberstormRes', validatorRules.cyberstormRes]" placeholder="请输入网络风暴 合格/不合格"></a-input>
        </a-form-item>
        <a-form-item label="雪崩试验 合格/不合格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'avalancheTestRes', validatorRules.avalancheTestRes]" placeholder="请输入雪崩试验 合格/不合格"></a-input>
        </a-form-item>
        <a-form-item label="对时 合格/不合格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'timingRes', validatorRules.timingRes]" placeholder="请输入对时 合格/不合格"></a-input>
        </a-form-item>
        <a-form-item label="通讯 合格/不合格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'communicationRes', validatorRules.communicationRes]" placeholder="请输入通讯 合格/不合格"></a-input>
        </a-form-item>
        <a-form-item label="SOE 合格/不合格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'soeRes', validatorRules.soeRes]" placeholder="请输入SOE 合格/不合格"></a-input>
        </a-form-item>
        <a-form-item label="监控系统图形组态测试 合格/不合格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'cadaGarConRes', validatorRules.cadaGarConRes]" placeholder="请输入监控系统图形组态测试 合格/不合格"></a-input>
        </a-form-item>
        <a-form-item label="监控软件功能 合格/不合格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'softWareFunctionRes', validatorRules.softWareFunctionRes]" placeholder="请输入监控软件功能 合格/不合格"></a-input>
        </a-form-item>
        <a-form-item label="连续运行 合格/不合格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'conOperationRes', validatorRules.conOperationRes]" placeholder="请输入连续运行 合格/不合格"></a-input>
        </a-form-item>
        <a-form-item label="供应商编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierCode', validatorRules.supplierCode]" placeholder="请输入供应商编号"></a-input>
        </a-form-item>
        <a-form-item label="1：未读（默认状态）
0：成功" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ioflag', validatorRules.ioflag]" placeholder="请输入1：未读（默认状态）
0：成功"></a-input>
        </a-form-item>
        <a-form-item label="完成时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择完成时间" v-decorator="[ 'endTime', validatorRules.endTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="装置编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'unitNo', validatorRules.unitNo]" placeholder="请输入装置编号"></a-input>
        </a-form-item>
        <a-form-item label="工艺编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processRouteNo', validatorRules.processRouteNo]" placeholder="请输入工艺编号"></a-input>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "ZxjEip2cXtldModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        salesOrdNo:{rules: [{ required: true, message: '请输入销售订单号!' }]},
        acsamplingRes:{rules: [{ required: true, message: '请输入交流采样 合格/不合格!' }]},
        openinLoopRes:{},
        openoutLoopRes:{rules: [{ required: true, message: '请输入开出回路 合格/不合格!' }]},
        cyberstormRes:{rules: [{ required: true, message: '请输入网络风暴 合格/不合格!' }]},
        avalancheTestRes:{rules: [{ required: true, message: '请输入雪崩试验 合格/不合格!' }]},
        timingRes:{rules: [{ required: true, message: '请输入对时 合格/不合格!' }]},
        communicationRes:{rules: [{ required: true, message: '请输入通讯 合格/不合格!' }]},
        soeRes:{rules: [{ required: true, message: '请输入SOE 合格/不合格!' }]},
        cadaGarConRes:{rules: [{ required: true, message: '请输入监控系统图形组态测试 合格/不合格!' }]},
        softWareFunctionRes:{rules: [{ required: true, message: '请输入监控软件功能 合格/不合格!' }]},
        conOperationRes:{rules: [{ required: true, message: '请输入连续运行 合格/不合格!' }]},
        supplierCode:{rules: [{ required: true, message: '请输入供应商编号!' }]},
        ioflag:{rules: [{ required: true, message: '请输入1：未读（默认状态）0：成功!' }]},
        endTime:{rules: [{ required: true, message: '请输入完成时间!' }]},
        unitNo:{rules: [{ required: true, message: '请输入装置编号!' }]},
        processRouteNo:{rules: [{ required: true, message: '请输入工艺编号!' }]},
        },
        url: {
          add: "/twice/zxjEip2cXtld/add",
          edit: "/twice/zxjEip2cXtld/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'salesOrdNo','acsamplingRes','openinLoopRes','openoutLoopRes','cyberstormRes','avalancheTestRes','timingRes','communicationRes','soeRes','cadaGarConRes','softWareFunctionRes','conOperationRes','supplierCode','ioflag','endTime','unitNo','processRouteNo'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'salesOrdNo','acsamplingRes','openinLoopRes','openoutLoopRes','cyberstormRes','avalancheTestRes','timingRes','communicationRes','soeRes','cadaGarConRes','softWareFunctionRes','conOperationRes','supplierCode','ioflag','endTime','unitNo','processRouteNo'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>